package crypt_kicker;

import java.io.*;
import java.util.*;
/*
 * Problem 110204
 * Algorithm: Some ridiculous backtracking scheme.
 */
class Main 
{
	public static void main(String [] args)
	{
		new CryptKicker().start();
	}
}

class CryptKicker
{
	static boolean DONE;
	
	public void start()
	{
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

		HashMap<String, String> letterEncryptionMap = new HashMap<String, String>();
		HashMap<String, String> letterDictionaryMap = new HashMap<String, String>();
		String [] dictionary;
		String [] encryption;
		
		String [] solutionArray;
	
		try
		{
			// Read the number of dictionary words used.
			int numOfDictWords = Integer.parseInt(reader.readLine());
			
			// Load read dictionary words it into an array.
			dictionary = loadDictionary(reader, numOfDictWords);
			
			// Read encryption sentence.
			String encryptSentence;
			
			while((encryptSentence = reader.readLine()) != null)
			{
				DONE = false;
				
				for (int i = 0; i < dictionary.length; i++)
				{
					encaseLetters(letterDictionaryMap, dictionary[i]);
				}

				// Load read encryption sentence into an array.
				encryption = loadEncryption(encryptSentence);
				
				encaseLetters(letterEncryptionMap, encryptSentence);
				
				solutionArray = new String[encryption.length];
				
				cryptTrack(solutionArray, dictionary, encryption, 0, letterEncryptionMap, letterDictionaryMap);
				
				if (DONE == false)
				{
					printNoSolution(encryption);
				}
				
				letterEncryptionMap.clear();
				letterDictionaryMap.clear();
			}
		}
		catch (IOException ex)
		{
			ex.printStackTrace();
		}
	}
	
	public void printNoSolution(String [] encryption)
	{
		String noSolution = "";
		
		for (int i = 1; i < encryption.length; i++)
		{
			String word = encryption[i];
			
			for (int j = 0; j < word.length(); j++)
			{
				noSolution += "*";
			}
				noSolution += " ";
		}
		
		System.out.println(noSolution.trim());
	}
	
	
	public void printResults(String [] solutionArray)
	{
		String result = "";
		
		for (int i = 1; i < solutionArray.length; i++)
		{
			result += solutionArray[i] + " ";
		}
		
		System.out.println(result.trim());
	}
	
	public String [] loadDictionary(BufferedReader reader, int numOfDictWords) 
	{
		String [] temp = new String[numOfDictWords];
		
		for (int count = 0; count < numOfDictWords; count++)
		{
			String word;
			try 
			{
				word = reader.readLine();
				temp[count] = word;
			} 
			catch (IOException e) 
			{
				e.printStackTrace();
			}
		}
		
		Arrays.sort(temp);
		
		return temp;
	}
	
	public String [] loadEncryption(String encryptSentence)
	{
		String [] temp = encryptSentence.split(" ");
		String [] encrypt = new String[temp.length + 1];
		
		for (int i = 0; i < temp.length; i++)
		{
			encrypt[i + 1] = temp[i];
		}
		
		return encrypt;
	}
	
	public void encaseLetters(HashMap<String, String> letterMap, String sentence)
	{
		for (int index = 0; index < sentence.length(); index++)
		{
			String character = sentence.substring(index, index + 1);
			
			if (!character.equals(" "))
			{
				letterMap.put(character, "");
			}
		}
	}
	
	public void encaseWords(HashMap<String, String> wordMap, String sentence)
	{
		String [] words = sentence.split(" ");
		
		for (int index = 0; index < words.length; index++)
		{
			wordMap.put(words[index], "");
		}
	}
	
	public void cryptTrack(String [] solArray, String [] dict, String [] encrypt, int k, HashMap<String, String> letterEncryptionMap, HashMap<String, String> letterDictionaryMap)
	{
		String [] candidates = new String[dict.length];
		
		int numOfCandidates;
		
		if (isSolution(solArray, encrypt, letterEncryptionMap, letterDictionaryMap) == true)
		{
			printResults(solArray);
		}
		else
		{
			k++;
			
			numOfCandidates = constructCandidates(k, candidates, dict, encrypt, letterEncryptionMap, letterDictionaryMap);
			
			for (int i = 0; i < numOfCandidates; i++)
			{
				solArray[k] = candidates[i];
				makeMove(candidates[i], k, encrypt, letterEncryptionMap, letterDictionaryMap);
				cryptTrack(solArray, dict, encrypt, k, letterEncryptionMap, letterDictionaryMap);
				
				if (DONE == true)
				{
					break;
				}
				
				unMakeMove(candidates[i], k, encrypt, solArray, letterEncryptionMap, letterDictionaryMap);
			}
		}
	}
	
	public boolean isSolution(String [] solArray, String [] encrypt,HashMap<String, String> letterEncryptionMap, HashMap<String, String> letterDictionaryMap)
	{
		// Make sure that the solution array is filled.
		for (int i = 1; i < solArray.length; i++)
		{
			if (solArray[i] == null)
			{
				return false;
			}
			else
			{
				// Verify that the solution array has a correct one-to-one mapping.
				String dictWord = solArray[i];
				String encryptWord = encrypt[i];
				
				if (verifyMapping(dictWord, encryptWord, letterEncryptionMap, letterDictionaryMap) != true)
				{
					return false;
				}
			}
		}
		
		DONE = true;
		
		return true;
	}
	
	public int constructCandidates(int k, String [] candidates, String [] dictionary, String [] encrypt,
			HashMap<String, String> letterEncryptionMap, HashMap<String, String> letterDictionaryMap)
	{
		int numOfCandidates = 0;
		
		// Verify that the length of potential candidates matches the length of
		// the encryption.
		String encryptionWord = encrypt[k];
		
		for (int i = 0; i < dictionary.length; i++)
		{
			String dictionaryWord = dictionary[i];
			
			if (dictionaryWord.length() == encryptionWord.length())
			{
				// Verify that there is a valid one-to-one
				// mapping between letters of the encryption
				// and letters of the dictionary word.
				if (verifyMapping(dictionaryWord, encryptionWord,
						letterEncryptionMap, letterDictionaryMap)
						&& checkDuplicates(dictionaryWord, encryptionWord))
				{
					candidates[numOfCandidates] = dictionaryWord;
					numOfCandidates++;
				}
			}
		}
		
		return numOfCandidates;
	}
	
	public boolean verifyMapping(String dictWord, String encryptWord, HashMap<String, String> letterEncryptionMap, HashMap<String, String> letterDictionaryMap)
	{
		for (int i = 0; i < encryptWord.length(); i++)
		{
			String encryptCharacter = "" + encryptWord.charAt(i);
			String dictCharacter = "" + dictWord.charAt(i);
			
			// Search for key/value pair in encryption map.
			String dictValue = letterEncryptionMap.get(encryptCharacter);
			
			// Search for key/value pair in dictionary map.
			String encryptValue = letterDictionaryMap.get(dictCharacter);
			
			if (!dictValue.equals(""))
			{
				if (!dictValue.equals(dictCharacter))
				{
					return false;
				}
			}
			
			if (!encryptValue.equals(""))
			{
				if (!encryptValue.equals(encryptCharacter))
				{
					return false;
				}
			}
		}
		
		return true;
	}
	
	public void makeMove(String candidate, int k, String [] encrypt, HashMap<String, String> letterEncryptionMap, 
			HashMap<String, String> letterDictionaryMap)
	{
		String encryptWord = encrypt[k];
		
		for (int i = 0; i < candidate.length(); i++)
		{
			letterEncryptionMap.put(encryptWord.charAt(i) + "", candidate.charAt(i) + "");
			letterDictionaryMap.put(candidate.charAt(i) + "", encryptWord.charAt(i) + "");
		}
	}
	
	public void unMakeMove(String candidate, int k, String [] encrypt, String [] solArray,
			HashMap<String, String> letterEncryptionMap,
			HashMap<String, String> letterDictionaryMap) 
	{
		String encryptWord = encrypt[k];
		
		// Clear the current mappings.
		for (int i = 0; i < encryptWord.length(); i++) 
		{
			letterEncryptionMap.put(encryptWord.charAt(i) + "", "");
			letterDictionaryMap.put(candidate.charAt(i) + "", "");
		}
		
		// And re-map it.
		for (int i = 1; i < k; i++)
		{
			String solArrayCand = solArray[i];
			encryptWord = encrypt[i];
				
			for (int j = 0; j < solArrayCand.length(); j++)
			{
				letterEncryptionMap.put(encryptWord.charAt(j) + "", solArrayCand.charAt(j) + "");
				letterDictionaryMap.put(solArrayCand.charAt(j) + "", encryptWord.charAt(j) + "");
			}
		}
		
		solArray[k] = null;
	}
	
	public boolean checkDuplicates(String dictionary, String encryption)
	{
		// Create a temp hashmap.
		HashMap<String, String> tempMap = new HashMap<String, String>();
		
		for (int i = 0; i < encryption.length(); i++)
		{
			String encryptionChar = encryption.charAt(i) + "";
			String dictChar = dictionary.charAt(i) + "";
			
			// Determine if hashmap already contains the key, which
			// is encryption letter at index 'i'.
			if (!tempMap.containsKey(encryptionChar))
			{	
				// If it doesn't, map key with value of dictionary letter
				// at index 'i'.
				tempMap.put(encryptionChar, dictChar);
			}
			else
			{
				// If it does, retrieve value of the key.
				String dictValue = tempMap.get(encryptionChar);
				
				// Determine if value matches the value being mapped.
				if (!dictValue.equals(dictChar))
				{
					return false;
				}
			}
		}
		return true;
	}
}